package com.fei.service;

import com.fei.bean.BroadcastBean;
import com.fei.bean.FileAudioBean;
import com.fei.mapper.BroadcastMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class FileAudioServiceImpl implements FileAudioService{

    @Autowired
    BroadcastMapper broadcastMapper;

    @Override
    public List<FileAudioBean> selectUserBroadcast(String phone) {
        List<BroadcastBean> list = broadcastMapper.selectOneUserId(phone);
        List<FileAudioBean> audio = new ArrayList<>();
        FileAudioBean fileAudioBean = null;
//        将数据库中获取用户的歌单信息，转换为jplayer需要的格式
        if(list != null){
            for (int i = 0;i<list.size();i++){
                fileAudioBean = new FileAudioBean();
                fileAudioBean.setMp3(list.get(i).getMusicBean().getMusic_path());
                fileAudioBean.setTitle(list.get(i).getMusicBean().getSong_title());
                fileAudioBean.setArtist(list.get(i).getMusicBean().getSingerBean().getName());
                audio.add(fileAudioBean);
            }
        }
        return audio;
    }

    @Override
    public FileAudioBean selectOneIdBroad(int id) {
        BroadcastBean broadcastBean = broadcastMapper.selectOneBroadId(id);
        FileAudioBean audio = new FileAudioBean();
        audio.setMp3(broadcastBean.getMusicBean().getMusic_path());
        audio.setTitle(broadcastBean.getMusicBean().getSong_title());
        audio.setArtist(broadcastBean.getMusicBean().getSingerBean().getName());
        return audio;
    }
}
